<?php

namespace Biz\model\salesRebate;

use Doraemon\pockets\datebase\BaseDbModel;

class SalesOrderLog extends BaseDbModel
{
    const _CONFIG_FILE_ = 'db_shop';

    const _CONFIG_SELECT_ = 'db_sales_rebate';

    const _DATABASE_ = 'biz_sales_rebate';

    const _TABLE_NAME = 'sales_order_log';

    const OPERATE_TYPE_CHANGE_RATE = 1;//管理员修改返佣比例


    public static function getAllByWhere($files = '*', $where = [])
    {
        $data = self::select($files, $where);
        return $data;
    }

    public static function getOneByWhere($files = '*', $where = [])
    {
        $data = self::get($files, $where);
        return $data;
    }

    public static function getOperateCount($salesOrderId, $operateType = self::OPERATE_TYPE_CHANGE_RATE)
    {
        $count = self::count(['sales_order_id' => $salesOrderId, 'operate_type' => $operateType]);
        return $count;
    }

    public static function addData($data)
    {
        $ret = self::insert($data);
        if ($ret->errorCode() !== '00000') {
            throw new \Exception('数据库操作错误');
        }
        return true;
    }

}